#include "SerialChannel.h"


BasicDevice SerialChannel::icSelector("/dev/uart_gpio0");
DummyChannel::Mutex SerialChannel::mallChannelMutex;


std::string& SerialChannel::sendStringReturnString(const std::string& parameter, std::string& result) {
    LOG_DEDUG("%s,sendStringReturnString:parameter:%s", mexceptionTip.data(), parameter.data());

    std::unique_lock<Mutex> locker(mallChannelMutex);
//    LOG_DEDUG("%s,begin write channel", mexceptionTip.data());
    ssize_t returnCode = ::write(icSelector.getDeviceFd(), &mchannel, sizeof (mchannel));
    if (0 < returnCode) {
//        LOG_DEDUG("%s,begin write serial data", mexceptionTip.data());
        returnCode = DummyChannel::write(parameter);
//        LOG_DEDUG("%s,begin read serial data", mexceptionTip.data());
        returnCode = DummyChannel::read(result);
    } else {
        BUILD_EXCEPTION_ERROR(FirmwareError::CHANNEL_COMM_ERROR, returnCode, errno, mexceptionTip);
    }
    locker.unlock();

    LOG_DEDUG("%s,sendStringReturnString:result:%s", mexceptionTip.data(), result.data());

    return result;
}






